package com.colodoo.code.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.HashSet;
import java.util.Set;

/**
 * 模块实体
 *
 * @author zhisan
 */
@Entity
@Table(name = "code_module_inf")
@Data
@EqualsAndHashCode(exclude = "tables")
public class ModuleInf {

	/**
	 * 模块ID
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "module_id")
	private Integer moduleId;

	/**
	 * 模块名
	 */
	@Column(name = "module_name")
	private String moduleName;

	/**
	 * 模块注释
	 */
	@Column(name = "module_comment")
	private String moduleComment;

	/**
	 * 父模块ID
	 */
	@Column(name = "parent_module_id")
	private String parentModuleId;

	/**
	 * 表
	 */
	@ManyToMany(targetEntity = TableInf.class, cascade = {CascadeType.ALL})
	@JoinTable(name = "code_module_table_rel",
			joinColumns = {@JoinColumn(name = "module_id", referencedColumnName = "module_id")},
			inverseJoinColumns = {@JoinColumn(name = "table_id", referencedColumnName = "table_id")}
	)
	private Set<TableInf> tables = new HashSet<TableInf>();

}
